package com.hyjx.framework.orm;

import com.hyjx.framework.common.CommonUtil;
import com.hyjx.framework.orm.dao.IBaseDao;
import com.hyjx.framework.orm.dao.Pager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 基础服务类
 */
@Service
public class BaseService implements IBaseService {
    
    @Resource
    private IBaseDao dao;
    
    @Override
    public String queryList(IBaseModel model) {
        
        Pager pager = dao.getPager(model.getModuleName() + ".queryList", model.getModuleName() + ".queryCount", model);
        return CommonUtil.getPageJsonStr(pager);
    }
    
    public Pager queryListA(IBaseModel model) {
        Pager pager = dao.getPager(model.getModuleName() + ".queryList", model.getModuleName() + ".queryCount", model);
        return pager;
    }
    
    @Override
    public boolean add(IBaseModel model) {
        return dao.addObject(model.getModuleName() + ".insert", model);
    }
    
    @Override
    public IBaseModel getInfoById(IBaseModel model) {
        return (IBaseModel) dao.queryObject(model.getModuleName() + ".getInfoById", model);
    }
    
    @Override
    public int edit(IBaseModel model) {
        return dao.updateObject(model.getModuleName() + ".update", model);
    }
    
    @Override
    public int delete(IBaseModel model) {
        return dao.deleteObject(model.getModuleName() + ".delete", model);
    }
    
}
